<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_job2dao/model')->方法名();
*/
namespace jy_job2dao;
defined('BY_JYA') or exit('error');
class member extends \plugin{
	public function onemember($postdata=array()){
		$isadd=pdo_getcolumn('jy_51job_member',array('openid'=>trim($postdata['openid']),'uniacid'=>$_SESSION['uniacid']),'mid');
		if($isadd){
			return '';
		}
		$mid=pdo_getcolumn('jy_job2dao_member',array('fmid'=>trim($postdata['uid']),'uniacid'=>$_SESSION['uniacid']),'mid');
		$data=array(
				'nickname'=>trim($postdata['name']),
				'mid'=>$mid,
				'mobile'=>trim($postdata['tel']),
				'createtime'=>trim($postdata['createtime']),
				'status'=>trim($postdata['status']),
				'avatar'=>trim($postdata['avatarUrl']),
				'merchid'=>trim($postdata['merchid']),
				'openid'=>trim($postdata['openid']),
		);
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_51job_member',$data);
		return '';
	}
	public function onefans($postdata=array(),$fans=array(),$wxgid=0){
		$data=array(
			'mobile'=>$postdata['mobile'],
			'email'=>$postdata['email'],
			'password'=>$postdata['password'],
			'salt'=>$postdata['salt'],
			'credit1'=>$postdata['credit1'],
			'credit2'=>$postdata['credit2'],
			'realname'=>$postdata['realname'],
			'nickname'=>$postdata['nickname'],
			'avatar'=>$postdata['avatar'],
			'qq'=>$postdata['qq'],
			'sex'=>$postdata['gender'],
			'birth'=>ijson_encode(array('year'=>$postdata['birthyear'],'month'=>$postdata['birthmonth'],'day'=>$postdata['birthday'])),
			'address'=>$postdata['address'],
			'cardnum'=>$postdata['idcard'],
			'paypassword'=>$postdata['pay_password'],
			'pcd'=>ijson_encode(array('province'=>$postdata['province'],'city'=>$postdata['city'])),
		);
		if($postdata['agentid']){
			$fromuser=pdo_getcolumn('jy_job2dao_member',array('fmid'=>$postdata['agentid'],'uniacid'=>$_SESSION['uniacid']),'mid');
			$data['fromuser']=$fromuser;
		}
		$mid=pdo_getcolumn('jy_job2dao_member',array('fmid'=>$postdata['uid'],'uniacid'=>$_SESSION['uniacid']),'mid');
		if($mid){
			pdo_update('core_members',$data,array('id'=>$mid,'uniacid'=>$_SESSION['uniacid']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['username']=$postdata['mobile']?:'fdao_'.$postdata['uid'];
			$data['from_os']=2;
			$data['createtime']=$postdata['createtime'];
			pdo_insert('core_members',$data);
			$mid=pdo_insertid();
			$newmember=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$mid,
				'fmid'=>$postdata['uid'],
			);
			pdo_insert('jy_job2dao_member',$newmember);
		}
		if($fans){
			$data=array(
				'openid'=>$fans['openid'],
				'follow'=>$fans['follow'],
				'nickname'=>$fans['nickname'],
				'avatar'=>$postdata['avatar'],
				'unionid'=>$fans['unionid'],
			);
			$fansid=pdo_getcolumn('core_fans',array('wxgid'=>$wxgid,'openid'=>$fans['openid'],'uniacid'=>$_SESSION['uniacid']),'id');
			if($fansid){
				//
			}else{
				$data['uniacid']=$_SESSION['uniacid'];
				$data['mid']=$mid;
				$data['wxgid']=$wxgid;
				$data['type']=2;
				$data['updatetime']=$fans['updatetime'];
				$data['createtime']=$fans['updatetime'];
				pdo_insert('core_fans',$data);
				pdo_update('jy_job2dao_member',array('openid'=>$fans['openid']),array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
			}
		}
		return $mid;
	}
	//搬移简历数据
	public function jianli($postdata=array(),$isup=false){
		$isadd=pdo_getcolumn('jy_51job_jianli',array('oid'=>$postdata['id'],'uniacid'=>$_SESSION['uniacid']),'id');
		if($isadd && !$isup){
			return '';
		}
		if($postdata['uid']){
			$mid=pdo_getcolumn('jy_job2dao_member',array('fmid'=>trim($postdata['uid']),'uniacid'=>$_SESSION['uniacid']),'mid');
		}else{
			$mid=0;
		}
		$pid=pdo_getcolumn('jy_51job_job_group',array('title'=>trim($postdata['jobgrouptitle']),'uniacid'=>$_SESSION['uniacid']),'id');
		if(!$pid){
			$newgroup=array(
				'uniacid'=>$_SESSION['uniacid'],
				'title'=>trim($postdata['jobgrouptitle']),
				'status'=>1,
				'createtime'=>time()
			);
			pdo_insert('jy_51job_job_group',$newgroup);
			$pid=pdo_insertid();
		}
		if($postdata['jobtype']=='全职'){
			$jobtype=0;
		}elseif($postdata['jobtype']=='兼职'){
			$jobtype=1;
		}elseif($postdata['jobtype']=='实习'){
			$jobtype=2;
		}
		$pcd=array('city'=>$postdata['city'],'district'=>$postdata['district']);
		$data=array(
			'oid'=>trim($postdata['id']),
			'title'=>trim($postdata['jobtitle']),
			'price'=>trim($postdata['money']),
			'mid'=>$mid,
			'name'=>trim($postdata['name']),
			'age'=>trim($postdata['birthday']),
			'education'=>trim($postdata['education']),
			'xueli'=>$this->xueli_type5[$postdata['education']],
			'express'=>trim($postdata['express']),
			'type'=>$jobtype,
			'mobile'=>trim($postdata['tel']),
			'sex'=>trim($postdata['sex']),
			'address'=>trim($postdata['address']),
			'email'=>trim($postdata['email']),
			'currentstatus'=>trim($postdata['currentstatus']),
			'thumb'=>trim($postdata['thumb']),
			'content'=>trim($postdata['content']),
			'pid'=>$pid,
			'city'=>$postdata['city'],
			'district'=>$postdata['district'],
			'pcd'=>ijson_encode($pcd),
			'status'=>$postdata['status']?0:1,
			'updatetime'=>trim($postdata['refreshtime']),
			'createtime'=>trim($postdata['createtime']),
		);
		if($isadd){
			pdo_update('jy_51job_jianli',$data,array('id'=>$isadd,'uniacid'=>$_SESSION['uniacid']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			pdo_insert('jy_51job_jianli',$data);
		}
		return '';
	}
}
?>